<!-- 爱计划 -->
<template>
  <div class="a-plane">
    <div class="top">
      <div class="show-type">
        <div
          :class="{ active: showType === 'week' }"
          @click="changeShowType('week')"
        >
          周
        </div>
        <div
          :class="{ active: showType === 'moth' }"
          @click="changeShowType('moth')"
        >
          月
        </div>
        <div
          class="bottom-tag"
          :class="{
            'to-right': showType === 'moth',
            'to-left': showType === 'week'
          }"
        ></div>
      </div>
      <div class="tools">
        <div class="btn-group" role="group" aria-label="Basic example">
          <button
            type="button"
            class="btn btn-primary btn-sm"
            @click="showDayReportFun('')"
          >
            <i class="fa-solid fa-calendar-day " aria-hidden="true"></i>
            日报
          </button>
          <button
            type="button"
            class="btn btn-primary btn-sm"
            @click="showWeekReportFun('')"
          >
            <i class="fa-regular fa-calendar-days " aria-hidden="true"></i>
            周报
          </button>
          <button
            type="button"
            class="btn btn-primary btn-sm"
            @click="reload()"
          >
            <i class="fa fa-refresh" aria-hidden="true"></i>
            刷新
          </button>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div>
        <div
          style="font-size: 1.2rem;font-weight: bold;color:var(--bs-primary);margin: 10px 0"
        >
          2023/01/01
        </div>
        <div>
          <div style="font-size: 1rem;font-weight: bold;color:#425365;">
            项目xxx
          </div>
          <div
            style="font-size: 0.8rem;margin: 10px 0;background: #fff;border-radius: 14px;padding: 10px 20px;display: flex;align-items: center"
          >
            <div style="font-size: 0.6rem;background: #69bfff;color: #fff;padding: 6px 16px;border-radius: 20px">进行中</div>
            <div
              style="width: 3px;background: #69bfff;margin: 0 16px;height: 2rem;border-radius: 10px"
            ></div>
            <div style="font-size: 0.6rem;font-weight: bold;background: #e7f5ff;color: #1687ff;padding: 6px 16px;border-radius: 20px;margin-right: 16px"><i class="fa-regular fa-clock "></i> 0.5D</div>
            <div>
              <div style="font-weight: bold;">标题标题</div>
              <div style="margin-top: 4px;">详细详细</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div
      class="modal-report"
      v-show="showDayReport"
      :style="{ opacity: showDayReportOpacity }"
    >
      <div class="modal-dialog-centered" style="height: 100%;">
        <div class="modal-report-div">
          <div class="modal-report-top">
            <span
              class="copy-text"
              :style="{ opacity: showDayReportTxtOpacity }"
              >已复制</span
            >
            <i class="fa fa-copy" @click="copyDayReport"> 拷贝</i>
            <i class="fa fa-close" @click="closeDayReportFun"></i>
          </div>
          <textarea id="dayReport"> </textarea>
        </div>
      </div>
    </div>

    <div
      class="modal-report"
      v-show="showWeekReport"
      :style="{ opacity: showWeekReportOpacity }"
    >
      <div class="modal-dialog-centered" style="height: 100%;">
        <div class="modal-report-div" style="height: calc(100% - 200px);">
          <div class="modal-report-top">
            <span
              class="copy-text"
              :style="{ opacity: showWeekReportTxtOpacity }"
              >已复制</span
            >
            <i class="fa-solid fa-paper-plane" @click="sendEmail"> 发周报</i>
            <i class="fa fa-copy" @click="copyWeekReport"> 拷贝</i>
            <i class="fa fa-close" @click="closeWeekReportFun"></i>
          </div>
          <textarea id="weekReport"> </textarea>
        </div>
      </div>
    </div>
    <div class="loading" :class="onload ? 'loading-show' : 'loading-hide'">
      <div class="icon">
        <i class="fa-solid fa-circle-notch "></i>
        <p>正在加载</p>
      </div>
    </div>
  </div>
</template>

<script>
const schedule = require("node-schedule");
import Swal from "sweetalert2";

let ipcRenderer;
if (window.require) {
  ipcRenderer = window.require("electron").ipcRenderer;
}
const nedb = require("nedb");
import { globalBus } from "@/assets/js/globalBus.js";

export default {
  components: {},
  data() {
    return {
      //任务类型数据库
      aplaneTypeDb: undefined,
      //任务数据库
      aplaneTodoDb: undefined,
      //当前加载的数据库
      startLoadDate: {
        year: "",
        moth: "",
        date: "",
        week: ""
      },
      //当前加载的数据库
      endLoadDate: {
        year: "",
        moth: "",
        date: "",
        week: ""
      },
      showType: "moth",
      showWeekReportBefore: false,
      dates: [],
      works: [],
      typeListMap: new Map(),
      typeTagMap: {},
      planeMap: new Map(), //按日期分类的全部任务
      types: [],
      typeDate: {},
      //table的移动缩放
      positionX: 0,
      positionY: 0,
      tableScale: 1,
      dateTag: new Map(), //用于更新日历打标记
      doTag: false, // 是否已打标标记
      choiceDate: {}, //当前日历选择的日期
      dbChoiceDate: {}, //当前db加载的日期
      showDayReport: false, //是否展示日报框
      showDayReportTxtOpacity: 0, //提示文字透明度
      showDayReportOpacity: 0, //拷贝弹窗显示透明度
      showWeekReport: false, //是否展示日报框
      showWeekReportTxtOpacity: 0, //提示文字透明度
      showWeekReportOpacity: 0, //拷贝弹窗显示透明度
      onload: false, //是否正在加载
      alyxAPP: {
        title: "阿里邮箱",
        img: "./static/img/apps/email.jpg",
        icon: "./static/img/apps/email_icon.png",
        info: "阿里邮箱",
        url: "https://qiye.aliyun.com/alimail/",
        loginUrl: "https://qiye.aliyun.com/alimail/auth/login",
        type: "web",
        code: "alyx"
      }
    };
  },
  created() {
    globalBus.$on("aPlane_reload", res => {
      setTimeout(() => {
        this.startLoadDate = {};
        this.endLoadDate = {};
        this.loadTypes();
      }, 500);
    });
    globalBus.$on("aPlane_changeShowTypeBack", res => {
      this.changeShowTypeBack(res);
    });
    globalBus.$on("aDate_changeDateBack", res => {
      this.choiceDate = res;
    });
  },
  methods: {
    getTdLeft(left, colspan) {
      return "calc(" + left * 100 + "%" + " + " + left + "px)";
    },
    sendEmail() {
      this.copyWeekReport();
      Swal.fire({
        title: `周报已拷贝-需要手动粘贴`,
        confirmButtonText: "明白！去发送"
      }).then(isConfirm => {
        if (isConfirm.isConfirmed) {
          globalBus.$emit("openApp", this.alyxAPP);
        }
      });
    },
    copyWeekReport() {
      let _this = this;
      let url = document.getElementById("weekReport");
      url.select(); // 选择对象
      document.execCommand("Copy");
      _this.showWeekReportTxtOpacity = 1;
      setTimeout(function() {
        _this.showWeekReportTxtOpacity = 0;
      }, 1500);
    },
    copyDayReport() {
      let _this = this;
      let url = document.getElementById("dayReport");
      url.select(); // 选择对象
      document.execCommand("Copy");
      _this.showDayReportTxtOpacity = 1;
      setTimeout(function() {
        _this.showDayReportTxtOpacity = 0;
      }, 1500);
    },
    closeWeekReportFun() {
      let _this = this;
      _this.showWeekReportOpacity = 0;
      setTimeout(function() {
        _this.showWeekReport = false;
      }, 200);
    },
    closeDayReportFun() {
      let _this = this;
      _this.showDayReportOpacity = 0;
      setTimeout(function() {
        _this.showDayReport = false;
      }, 200);
    },
    //日报
    showDayReportFun() {
      let _this = this;
      _this.showDayReport = true;
      setTimeout(function() {
        _this.showDayReportOpacity = 1;
      }, 50);

      let date = this.choiceDate;

      if (
        this.dbChoiceDate.year !== date.year ||
        this.dbChoiceDate.month !== date.moth
      ) {
        _this.aplaneTodoDb = new nedb({
          filename: "/data/aplane-todo_" + date.year + "-" + date.moth + ".db",
          autoload: true
        });
        _this.dbChoiceDate = {
          year: date.year,
          month: date.moth
        };
      }

      let dayReport = document.getElementById("dayReport");
      if (!_this.showDayReport || !dayReport) return;
      // 查询所有结果集
      _this.aplaneTodoDb.find(
        {
          year: date.year,
          moth: date.moth,
          date: date.date
        },
        function(err, docs) {
          let timeNow = new Date();
          let dayEndTag = timeNow.getHours() > 12;
          let allTxt = dayEndTag ? "今日完成\n" : "今日计划\n";
          let i = 0;
          docs.sort((a, b) =>
            (a.scope + a.sort + "").localeCompare(b.scope + b.sort + "")
          );
          for (let x in docs) {
            let time = docs[x].time ? parseFloat(docs[x].time) : 0;
            allTxt +=
              ++i +
              ". " +
              (docs[x].scope ? docs[x].scope + "：" : "") +
              docs[x].type +
              "：" +
              docs[x].title +
              (dayEndTag
                ? docs[x].status === "已完成"
                  ? "[已完成]"
                  : "[进行中]"
                : "") +
              " " +
              (time ? time + "d" : "") +
              "\n";
          }
          document.getElementById("dayReport").value = allTxt.trim();
        }
      );
    },
    //周报
    showWeekReportFun() {
      if (this.showType !== "week") {
        this.showWeekReportBefore = true;
        this.changeShowType("week");
        return;
      }
      let _this = this;
      let timeCountMap = new Map(); // 工时合并
      let timeProcessMap = new Map(); // 工时占比
      let allTime = 0; //总耗时
      let loopDates;
      let start = 0;
      let end = 7;

      let jsyf = [];
      let zxxq = [];
      let bug = [];
      let dzkf = [];
      let dwzc = [];
      let qt = [];
      let date =
        this.dates[0].year +
        "-" +
        this.dates[0].moth +
        "-" +
        this.dates[0].date;
      let ds = _this.planeMap.get(date);
      if (!ds || ds.length === 0) {
        start = 1;
      }
      date =
        this.dates[_this.dates.length - 1].year +
        "-" +
        this.dates[_this.dates.length - 1].moth +
        "-" +
        this.dates[_this.dates.length - 1].date;
      ds = _this.planeMap.get(date);
      if (!ds || ds.length === 0) {
        end = 6;
      }
      loopDates = _this.dates.slice(start, end);
      let allTxt =
        "本周工作（" +
        (loopDates[0].moth + 1) +
        "." +
        loopDates[0].date +
        "~" +
        (loopDates[loopDates.length - 1].moth + 1) +
        "." +
        loopDates[loopDates.length - 1].date +
        "）\n";
      for (let x in loopDates) {
        let w;
        switch (parseInt(x) + start) {
          case 0:
            w = "日";
            break;
          case 1:
            w = "一";
            break;
          case 2:
            w = "二";
            break;
          case 3:
            w = "三";
            break;
          case 4:
            w = "四";
            break;
          case 5:
            w = "五";
            break;
          case 6:
            w = "六";
            break;
        }
        allTxt +=
          "周" +
          w +
          "（" +
          (loopDates[x].moth + 1) +
          "." +
          loopDates[x].date +
          "）\n";
        let date =
          loopDates[x].year + "-" + loopDates[x].moth + "-" + loopDates[x].date;
        //每一天的工作内容
        let data = _this.planeMap.get(date);
        let i = 0;

        data.sort((a, b) =>
          (a.scope + a.sort + "").localeCompare(b.scope + b.sort + "")
        );

        for (let x in data) {
          let time = data[x].time ? parseFloat(data[x].time) : 0;

          allTxt +=
            ++i +
            ". " +
            (data[x].scope ? data[x].scope + "：" : "") +
            (data[x].type ? data[x].type + "：" : "") +
            data[x].title +
            (data[x].status === "已完成" ? "[已完成]" : "[进行中]") +
            " " +
            (time ? time + "d" : "") +
            "\n";

          let scope = data[x].scope
            ? (data[x].scope === "BUG" ? "bug" : data[x].scope) + "："
            : "";
          let timeCountKey = scope + (data[x].type ? data[x].type + "：" : "");
          let timeCount = timeCountMap.get(timeCountKey);
          if (timeCount === undefined) {
            if (data[x].scope === "技术研发") {
              jsyf.push(timeCountKey);
            } else if (data[x].scope === "主线需求") {
              zxxq.push(timeCountKey);
            } else if (data[x].scope === "BUG") {
              bug.push(timeCountKey);
            } else if (data[x].scope === "定制开发") {
              dzkf.push(timeCountKey);
            } else if (data[x].scope === "对外支持") {
              dwzc.push(timeCountKey);
            } else {
              qt.push(timeCountKey);
            }
          }
          timeCount = timeCount ? timeCount : 0;
          timeCountMap.set(timeCountKey, timeCount + time);

          let timeProcess = timeProcessMap.get(data[x].scope);
          timeProcess = timeProcess ? timeProcess : 0;
          timeProcessMap.set(
            data[x].scope ? data[x].scope : "其他",
            timeProcess + time
          );

          allTime += time;
        }
        allTxt += "\n";
      }

      this.loadNextWeekPlane(text => {
        allTxt += "工时合并:\n";

        jsyf.sort();
        zxxq.sort();
        bug.sort();
        dzkf.sort();
        dwzc.sort();
        qt.sort();
        jsyf.forEach(v => {
          allTxt += v + timeCountMap.get(v).toFixed(1) + "d\n";
        });
        zxxq.forEach(v => {
          allTxt += v + timeCountMap.get(v).toFixed(1) + "d\n";
        });
        bug.forEach(v => {
          allTxt += v + timeCountMap.get(v).toFixed(1) + "d\n";
        });
        dzkf.forEach(v => {
          allTxt += v + timeCountMap.get(v).toFixed(1) + "d\n";
        });
        dwzc.forEach(v => {
          allTxt += v + timeCountMap.get(v).toFixed(1) + "d\n";
        });
        qt.forEach(v => {
          allTxt += v + timeCountMap.get(v).toFixed(1) + "d\n";
        });

        allTxt += "\n";
        allTxt += "下周计划:\n";
        allTxt += text;
        allTxt += "\n";

        allTxt += "本周工作时间占比:\n";
        allTxt +=
          "1. 技术研发:\t\t" +
          Math.round(
            ((timeProcessMap.get("技术研发")
              ? timeProcessMap.get("技术研发")
              : 0) /
              allTime) *
              100
          ) +
          "%\n";
        allTxt +=
          "2. 主线需求:\t\t" +
          Math.round(
            ((timeProcessMap.get("主线需求")
              ? timeProcessMap.get("主线需求")
              : 0) /
              allTime) *
              100
          ) +
          "%\n";
        allTxt +=
          "3. bug:      \t\t" +
          Math.round(
            ((timeProcessMap.get("BUG") ? timeProcessMap.get("BUG") : 0) /
              allTime) *
              100
          ) +
          "%\n";
        allTxt +=
          "4. 定制开发:\t\t" +
          Math.round(
            ((timeProcessMap.get("定制开发")
              ? timeProcessMap.get("定制开发")
              : 0) /
              allTime) *
              100
          ) +
          "%\n";
        allTxt +=
          "5. 对外支持:\t\t" +
          Math.round(
            ((timeProcessMap.get("对外支持")
              ? timeProcessMap.get("对外支持")
              : 0) /
              allTime) *
              100
          ) +
          "%\n";
        if (qt.length > 0) {
          allTxt +=
            "6. 其他:\t\t" +
            Math.round(
              ((timeProcessMap.get("其他") ? timeProcessMap.get("其他") : 0) /
                allTime) *
                100
            ) +
            "%\n";
        }

        document.getElementById("weekReport").value = allTxt.trim();
        _this.showWeekReport = true;
        setTimeout(function() {
          _this.showWeekReportOpacity = 1;
        }, 50);
      });
    },
    //加载下周计划
    loadNextWeekPlane(callBack) {
      let _this = this;
      let db = _this.aplaneTodoDb;
      let choiceDate = this.dates[6];
      let newDate = new Date(choiceDate.year, choiceDate.moth, choiceDate.date);
      let moth = choiceDate.moth;
      let text = "";
      let count = 0;
      let data = [];
      for (let x = 0; x <= 6; x++) {
        (function(xx) {
          newDate.setDate(newDate.getDate() + 1);
          if (newDate.getMonth() !== moth) {
            moth = newDate.getMonth();
            db = new nedb({
              filename:
                "/data/aplane-todo_" +
                newDate.getFullYear() +
                "-" +
                newDate.getMonth() +
                ".db",
              autoload: true
            });
          }
          db.find(
            {
              year: newDate.getFullYear(),
              moth: newDate.getMonth(),
              date: newDate.getDate()
            },
            function(err, res) {
              data = data.concat(res);
              if (xx === 6) {
                data = data.sort((a, b) =>
                  (a.scope + a.type).localeCompare(b.scope + b.type)
                );
                for (let x in data) {
                  text +=
                    ++count +
                    ". " +
                    (data[x].scope ? data[x].scope + "：" : "") +
                    (data[x].type ? data[x].type + "：" : "") +
                    data[x].title +
                    "\n";
                }
                callBack(text);
              }
            }
          );
        })(x);
      }
    },
    getFontSize(txt) {
      return txt.length > 10 ? "0.8rem" : "1rem";
    },
    //计算占据宽度 col自身比例  allCol总的宽比
    getTdWidth(col, allCol) {
      return "calc(" + col * 100 + "% - 10px)";
    },
    reload() {
      this.startLoadDate = {};
      this.endLoadDate = {};
      this.loadTypes();
      this.reloadTable();
    },
    reloadTable() {
      this.positionX = 0;
      this.positionY = 0;
      this.tableScale = 1;
    },
    move(e) {
      //算出鼠标相对元素的位置
      let disX = e.clientX;
      let disY = e.clientY;
      let oldX = this.positionX;
      let oldY = this.positionY;
      document.onmousemove = e => {
        //鼠标按下并移动的事件
        //用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
        let left = e.clientX - disX;
        let top = e.clientY - disY;
        //绑定元素位置到positionX和positionY上面
        this.positionX = oldX + left;
        this.positionY = oldY + top;
      };
      document.onmouseup = e => {
        document.onmousemove = null;
        document.onmouseup = null;
      };
    },
    changeShowTypeBack(res) {
      let _this = this;
      if (_this.onload) {
        return;
      }
      _this.onload = true;

      _this.dates.splice(0, _this.dates.length);
      _this.works.splice(0, _this.works.length);
      _this.planeMap.clear();
      _this.typeListMap.forEach(function(value, key) {
        value.splice(0, value.length);
      });
      _this.typeTagMap = {};

      if (this.showType === "moth") {
        if (
          _this.startLoadDate.year + "-" + _this.startLoadDate.moth !==
          res.year + "-" + res.moth
        ) {
          _this.aplaneTodoDb = new nedb({
            filename: "/data/aplane-todo_" + res.year + "-" + res.moth + ".db",
            autoload: true
          });
          _this.dbChoiceDate = {
            year: res.year,
            month: res.moth
          };
        }
        _this.startLoadDate = res;
        let monthEndDate = new Date(res.year, res.moth + 1, 0).getDate();
        for (let x = 1; x <= monthEndDate; x++) {
          _this.dateTag.set(res.year + "-" + res.moth + "-" + x, false);
          _this.dates.push({
            year: res.year,
            moth: res.moth,
            date: x
          });
          (function(x, max) {
            _this.findAndAddPlane({
              year: res.year,
              moth: res.moth,
              date: x,
              max: max,
              x: x
            });
          })(x, monthEndDate);
        }
      } else if (res.dates && res.dates.length > 0) {
        let startDate = res.dates[0];
        _this.endLoadDate = startDate;
        _this.startLoadDate = startDate;
        _this.aplaneTodoDb = new nedb({
          filename:
            "/data/aplane-todo_" +
            startDate.year +
            "-" +
            startDate.moth +
            ".db",
          autoload: true
        });
        _this.dbChoiceDate = {
          year: startDate.year,
          month: startDate.moth
        };
        for (let x = 0; x < res.dates.length; x++) {
          this.dates.push({
            year: res.dates[x].year,
            moth: res.dates[x].moth,
            date: res.dates[x].date
          });
          _this.dateTag.set(
            res.dates[x].year +
              "-" +
              res.dates[x].moth +
              "-" +
              res.dates[x].date,
            false
          );
          //进入另一个月份
          if (
            res.dates[x].year !== _this.endLoadDate.year ||
            res.dates[x].moth !== _this.endLoadDate.moth
          ) {
            _this.aplaneTodoDb = new nedb({
              filename:
                "/data/aplane-todo_" +
                res.dates[x].year +
                "-" +
                res.dates[x].moth +
                ".db",
              autoload: true
            });
            _this.endLoadDate = res.dates[x];
            _this.dbChoiceDate = {
              year: res.dates[x].year,
              month: res.dates[x].moth
            };
          }
          (function(x, max) {
            _this.findAndAddPlane({
              year: res.dates[x].year,
              moth: res.dates[x].moth,
              date: res.dates[x].date,
              max: max,
              x: x
            });
          })(x, res.dates.length - 1);
        }
      } else {
        this.onload = false;
      }
      _this.typeListMap.forEach(function(value, key) {
        _this.works.push({
          type: key,
          data: value
        });
      });
    },
    //res 日期 找到这个日期下所有计划
    findAndAddPlane(res) {
      let _this = this;
      // 查询所有结果集
      _this.aplaneTodoDb.find(
        {
          year: res.year,
          moth: res.moth,
          date: res.date
        },
        function(err, docs) {
          _this.planeMap.set(res.year + "-" + res.moth + "-" + res.date, docs);
          //先添加一个空计划占行
          _this.typeListMap.forEach(function(value, key) {
            value.push({
              colspan: 1,
              data: [],
              show: true
            });
          });
          //遍历找到的全部计划
          for (let x in docs) {
            //如果找不到对应分类就是其他
            let type = docs[x].type ? docs[x].type : "其他";
            if (!_this.typeListMap.get(type)) {
              type = "其他";
            }
            //默认一个任务一天
            docs[x].colspan = 1;
            docs[x].show = true;

            //获取这个分类下所及计划 把计划归到这下面
            let data = _this.typeListMap.get(type);
            if (data.length > 1) {
              let pyl = 1; //便偏移量
              for (let y = data.length - 2; y >= 0; y--, pyl++) {
                let beforDatas = data[y]; //前一天的任务
                if (!beforDatas.show) {
                  continue;
                }
                for (let i in beforDatas.data) {
                  if (docs[x].title === beforDatas.data[i].title) {
                    //如果前一天有同一个任务就不在添加  把天数+1
                    beforDatas.colspan++;
                    beforDatas.data[i].status =
                      beforDatas.data[i].status !== "已完成"
                        ? "延期"
                        : beforDatas.data[i].status;
                    beforDatas.data[i].colspan++;
                    if (
                      data[data.length - 1].data.length > 0 &&
                      data[data.length - 1].show
                    ) {
                      for (let dd in data[data.length - 1].data) {
                        data[data.length - 1].data[dd].left = pyl;
                        beforDatas.data.push(data[data.length - 1].data[dd]);
                      }
                    }
                    data[data.length - 1].show = false;
                    docs[x].show = false;
                  }
                }
                break;
              }
            }
            if (!data[data.length - 1].show && docs[x].show) {
              let pyl = 0; //便偏移量
              for (let y = data.length - 1; y >= 0; y--, pyl++) {
                let beforDatas = data[y]; //前一天的任务
                if (beforDatas.show) {
                  docs[x].left = pyl;
                  beforDatas.data.push(docs[x]);
                  _this.typeTagMap[type] = true;
                  break;
                }
              }
            }
            _this.dateTag.set(res.year + "-" + res.moth + "-" + res.date, true);
            data[data.length - 1].data.push(docs[x]);
            _this.typeTagMap[type] = true;
          }
          if (res.x === res.max) {
            _this.reloadTable();
            //通知日历打标
            globalBus.$emit("aDate_tag", _this.dateTag);
            _this.onload = false;
            if (_this.showWeekReportBefore) {
              _this.showWeekReportBefore = false;
              _this.showWeekReportFun("");
            }
            if (!_this.doTag) {
              _this.doTag = true;
              _this.changeShowType("week");
            }
          }
        }
      );
    },
    changeShowType(type) {
      if (this.showType !== type) {
        this.reloadTable();
      }
      this.showType = type;
      globalBus.$emit("aDate_getDateList", type);
    },
    loadTypes() {
      let _this = this;
      if (_this.onload) {
        return;
      }
      _this.onload = true;
      _this.typeTagMap = {};
      _this.typeListMap.clear();
      _this.typeListMap.set("其他", []);
      _this.aplaneTypeDb = new nedb({
        filename: "/data/aplane-type.db",
        autoload: true
      });
      // 查询所有结果集
      _this.aplaneTypeDb.find({}, function(err, docs) {
        for (let x in docs) {
          _this.typeListMap.set(docs[x].name, []);
        }
        _this.onload = false;
        if (_this.showType) {
          _this.changeShowType(_this.showType);
        } else {
          _this.changeShowType("moth");
        }
      });
    }
  },
  mounted() {
    this.loadTypes();
    let _this = this;
    this.$nextTick(function() {
      let scrollFunc = function(e) {
        e = e || window.event;
        if (e.wheelDelta) {
          //判断浏览器IE，谷歌滑轮事件
          if (e.wheelDelta > 0) {
            //当滑轮向上滚动时
            if (_this.tableScale > 1.5) {
              return;
            }
            _this.tableScale += 0.1;
          }
          if (e.wheelDelta < 0) {
            //当滑轮向下滚动时
            if (_this.tableScale < 0.6) {
              return;
            }
            _this.tableScale -= 0.1;
          }
        } else if (e.detail) {
          //Firefox滑轮事件
          if (e.detail > 0) {
            //当滑轮向上滚动时
            if (_this.tableScale > 1.5) {
              return;
            }
            _this.tableScale += 0.1;
          }
          if (e.detail < 0) {
            //当滑轮向下滚动时
            if (_this.tableScale < 0.6) {
              return;
            }
            _this.tableScale -= 0.1;
          }
        }
      };
      //给页面绑定滑轮滚动事件
      if (this.$refs.table.addEventListener) {
        this.$refs.table.onmousewheel = scrollFunc;
      }
      //滚动滑轮触发scrollFunc方法
    });
    if (ipcRenderer) {
      schedule.scheduleJob("30 0 17 * * *", () => {
        ipcRenderer.send("show-notification", {
          title: "爱工作-提醒",
          body: "快下班啦！记得发送日报哦！"
        });
      });
    }
  }
};
</script>

<style lang="less">
@keyframes toRightKF {
  0% {
    left: 0;
    width: 2rem;
  }

  50% {
    left: 0%;
    width: 4rem;
  }

  100% {
    left: 50%;
    width: 2rem;
  }
}

@keyframes toLeftKF {
  0% {
    left: 50%;
    width: 2rem;
  }

  50% {
    left: 0%;
    width: 4rem;
  }

  100% {
    left: 0;
    width: 2rem;
  }
}

.a-plane {
  height: 100%;
  box-sizing: border-box;
  display: flex;
  padding: 14px;
  flex-direction: column;
  background: #f1f7f7;

  .modal-report {
    transition: all 0.2s ease-in-out;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    padding-left: 60px;

    .modal-report-div {
      width: 700px;
      max-width: calc(100% - 60px);
      height: 500px;
      background: #ffffff;
      margin: 100px auto;
      border-radius: 4px;
      box-sizing: border-box;
      padding: 20px;
      display: flex;
      flex-direction: column;

      textarea {
        margin-top: 10px;
        width: 100%;
        flex: 1;
        border: none;
        outline: none;
        resize: none;
        color: #607d8b;
      }

      .modal-report-top {
        text-align: right;

        i {
          margin-left: 10px;
          cursor: pointer;
          color: #607d8b;
        }

        i:hover {
          color: #03a9f4;
        }

        .copy-text {
          transition: all 0.2s ease-in-out;
          font-size: 0.8rem;
          color: #7092a2;
          opacity: 0;
        }
      }
    }
  }

  .bottom {
    width: 100%;
    flex: 1;
    padding-top: 4px;
    overflow: hidden;
  }

  .top {
    padding-bottom: 10px;
    border-bottom: 1px rgba(#eceff1, 0.6) solid;
    display: flex;
    color: #90a4ae;

    .tools {
      flex: 1;
      text-align: right;

      .item {
        display: inline-flex;
        line-height: 1rem;
        cursor: pointer;
        margin-left: 10px;
        transition: all 0.2s linear;

        div {
          font-size: 0.8rem;
          margin-left: 4px;
          transition: all 0.2s linear;
          display: inline-block;
          width: 0px;
          overflow: hidden;
          white-space: nowrap;
        }
      }

      .item:hover {
        color: #1e88e5;

        div {
          //width: 3.2rem;
        }
      }
    }

    .show-type {
      margin-top: 0.2rem;
      height: 1.4rem;
      display: flex;
      position: relative;

      .to-right {
        animation: toRightKF 0.5s;
        animation-fill-mode: forwards;
      }

      .to-left {
        animation: toLeftKF 0.5s;
        animation-fill-mode: forwards;
      }

      .bottom-tag {
        border-radius: 4px;
        height: 3px;
        width: 2rem;
        background: var(--bs-primary);
        position: absolute;
        bottom: -4px;
      }

      div {
        width: 2rem;
        cursor: pointer;
        text-align: center;
        line-height: 1.2rem;
        transition: all 0.1s linear;
      }

      div:hover {
        color: var(--bs-primary);
      }

      .active {
        font-weight: bold;
        font-size: 1.2rem;
        color: var(--bs-primary);
        width: 2rem;
        //  border-bottom: 3px #1E88E5 solid;
        padding-bottom: 4px;
      }
    }
  }
}
</style>
